package com.andy.blog.admin.controller;

import com.andy.blog.admin.service.SysUserOnlineBusService;
import com.andy.blog.common.annotation.Log;
import com.andy.blog.common.enums.BusinessTypeEnum;
import com.andy.blog.common.page.PageUtilsDTO;
import com.andy.blog.common.reponse.GeneralResponseResult;
import com.andy.blog.dal.domain.SysUserOnlineDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 在线用户监控
 * Created by andy on 2023-04-05 11:38
 */
@RestController
@RequestMapping("/monitor/online")
public class SysUserOnlineController  {

    @Resource
    private SysUserOnlineBusService sysUserOnlineBusService;

    /**
     * 分页查询
     */
    @PreAuthorize("@ss.hasPermi('monitor:online:list')")
    @GetMapping("/list")
    public GeneralResponseResult<PageUtilsDTO<SysUserOnlineDTO>> list(String ipaddr, String userName) {
        return GeneralResponseResult.success(sysUserOnlineBusService.selectListByPage(ipaddr, userName));
    }

    /**
     * 强退用户
     */
    @PreAuthorize("@ss.hasPermi('monitor:online:forceLogout')")
    @Log(title = "在线用户", businessType = BusinessTypeEnum.FORCE)
    @DeleteMapping("/{tokenId}")
    public GeneralResponseResult<Void> forceLogout(@PathVariable String tokenId) {
        sysUserOnlineBusService.forceLogout(tokenId);
        return GeneralResponseResult.success();
    }
}
